package com.oasystem.web.controller.profit;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.oasystem.domain.PagingBean;
import com.oasystem.domain.ProfitSearchResult;
import com.oasystem.domain.ProfitSummary;
import com.oasystem.service.ProfitService;

@Controller
@RequestMapping(value = "/MainMenu/profit")
public class ProfitSummaryController {
	@Resource(name = "profitService")
	private ProfitService profitService;

	@RequestMapping(value = "/profitStatistics")
	public @ResponseBody
	ModelMap profitStatistics(String from, String to) {
		ModelMap model = new ModelMap();
		try {

			ProfitSummary summary = profitService.loadProfitSummary(from, to);
			model.addAttribute("profitSummary", summary);
			model.addAttribute("isSuccessfull", Boolean.TRUE);
		} catch (Exception e) {
			model.addAttribute("isSuccessfull", Boolean.FALSE);
		}
		return model;
	}

	@RequestMapping(value = "/profitDetailsSearch")
	public String profitDetailsSearch(String from, String to, String pageIndex,
			Model model) {
		PagingBean<ProfitSearchResult> pagingBean = new PagingBean<ProfitSearchResult>();
		pagingBean.setPageSize(10);
		pagingBean.setCurrentPage(Integer.valueOf(pageIndex));
		profitService.retrieveProfitDetails(from, to, pagingBean);
		model.addAttribute("pagingBean", pagingBean);
		return "profit.detailsResult";
	}

}
